package cn.hdu.liang.observer.weatherobservable;

import java.util.Observable;
import java.util.Observer;

public class CurrentConditionDisplay implements Observer, DisplayElement {

    private double temp;
    private double humidity;
    private Observable observable;

    public CurrentConditionDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    public void display() {
        System.out.println("当前状态： " + temp + "华氏度 " + humidity + "% 湿度");
    }


    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData) {
            WeatherData wd = (WeatherData) o;
            this.temp = wd.getTemp();
            this.humidity = wd.getHumidity();
            display();
        }
    }
}
